/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaPrincipal.java
 *
 * Created on 12/03/2011, 18:45:56
 */
package gui;

import java.util.List;
import javax.swing.JOptionPane;
import negocio.NegocioCadastroLei;

/**
 *
 * @author emersonmx
 */
public class JanelaPrincipal extends javax.swing.JFrame implements UI {

  /** Creates new form JanelaPrincipal */
  public JanelaPrincipal() {
    initComponents();
    janelaCadastroUsuario = new JanelaCadastroUsuario(this, rootPaneCheckingEnabled);
    Controlador controladorCadastroUsuario = new ControladorCadastroUsuario();
    janelaCadastroUsuario.setControlador(controladorCadastroUsuario);
    controladorCadastroUsuario.setUI(janelaCadastroUsuario);

    janelaRevogarLei = new JanelaRevogarLei();
    janelaCadastrarLei = new JanelaCadastrarLei(this, rootPaneCheckingEnabled);
    janelaPesquisarLei = new JanelaPesquisarLei();
    janelaAlterarLei = new JanelaAlterarLei();
    janelaResultadoPesquisa = new JanelaResultadoPesquisa();
    janelaModificarLei = new JanelaModificarLei();

    Controlador controladorCadastroLei = new ControladorCadastroLei();
    Controlador controladorPesquisaLei = new ControladorPesquisaLei();
    ControladorRevogarLei controladorRevogarLei = new ControladorRevogarLei();
    controladorRevogarLei.setUI(janelaRevogarLei);
    janelaRevogarLei.setControladorRevogarLei(controladorRevogarLei);
    janelaRevogarLei.setJanelaPesquisarLei(janelaPesquisarLei);
    controladorCadastroLei.setUI(janelaCadastrarLei);
    janelaModificarLei.setControlador(controladorCadastroLei);
    controladorCadastroLei.setJanelaModificarLei(janelaModificarLei);
    janelaCadastrarLei.setControlador(controladorCadastroLei);
    controladorPesquisaLei.setUI(janelaPesquisarLei);
    janelaResultadoPesquisa.setJanelaModificarLei(janelaModificarLei);
    janelaPesquisarLei.setControladorPesquisaLei(controladorPesquisaLei);
    janelaResultadoPesquisa.setControlador(controladorPesquisaLei);
    janelaPesquisarLei.setJanelaResultadoPesquisa(janelaResultadoPesquisa);
    controladorPesquisaLei.setJanelaResultado(janelaResultadoPesquisa);
    ControladorAlterarLei controladorAlterarLei = new ControladorAlterarLei();
    janelaAlterarLei.setControladorAlterarLei(controladorAlterarLei);
    janelaAlterarLei.setJanelaCadastrarLei(janelaCadastrarLei);
    controladorAlterarLei.setUI(janelaAlterarLei);
    setLocationRelativeTo(null);
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        imgLogo = new javax.swing.JLabel();
        botaoCadastrarLei = new javax.swing.JButton();
        botaoAlterarLei = new javax.swing.JButton();
        botaoExcluirLei = new javax.swing.JButton();
        botaoPesquisarLei = new javax.swing.JButton();
        botaoGerenciarUsuario = new javax.swing.JButton();
        botaoSair = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SIGLEM - Sistema Gerenciador de Leis Municipais");
        setResizable(false);

        imgLogo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        imgLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/prefeitura3.jpg"))); // NOI18N
        imgLogo.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        botaoCadastrarLei.setText("Cadastrar Lei");
        botaoCadastrarLei.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCadastrarLeiActionPerformed(evt);
            }
        });

        botaoAlterarLei.setText("Alterar Lei");
        botaoAlterarLei.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAlterarLeiActionPerformed(evt);
            }
        });

        botaoExcluirLei.setText("Revogar Lei");
        botaoExcluirLei.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoExcluirLeiActionPerformed(evt);
            }
        });

        botaoPesquisarLei.setText("Pesquisar Lei");
        botaoPesquisarLei.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoPesquisarLeiActionPerformed(evt);
            }
        });

        botaoGerenciarUsuario.setText("Gerenciar Usuário");
        botaoGerenciarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoGerenciarUsuarioActionPerformed(evt);
            }
        });

        botaoSair.setText("Sair");
        botaoSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSairActionPerformed(evt);
            }
        });

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/crz.jpg"))); // NOI18N
        jLabel2.setText("jLabel2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imgLogo, javax.swing.GroupLayout.DEFAULT_SIZE, 738, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(botaoCadastrarLei, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addComponent(botaoGerenciarUsuario, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(botaoAlterarLei, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(14, 14, 14)
                                .addComponent(botaoExcluirLei, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1)))
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(botaoSair, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(botaoPesquisarLei, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imgLogo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoExcluirLei)
                    .addComponent(botaoPesquisarLei)
                    .addComponent(botaoCadastrarLei)
                    .addComponent(botaoAlterarLei))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(botaoGerenciarUsuario)
                        .addComponent(botaoSair))
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoCadastrarLeiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCadastrarLeiActionPerformed
      janelaCadastrarLei.setVisible(true);
      janelaCadastrarLei.limparCampos();
    }//GEN-LAST:event_botaoCadastrarLeiActionPerformed

    private void botaoAlterarLeiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAlterarLeiActionPerformed
      janelaAlterarLei.carregarDados();
      janelaAlterarLei.setVisible(true);
    }//GEN-LAST:event_botaoAlterarLeiActionPerformed

    private void botaoExcluirLeiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoExcluirLeiActionPerformed
        janelaRevogarLei.setVisible(true);
        janelaRevogarLei.limparTela();
    }//GEN-LAST:event_botaoExcluirLeiActionPerformed

    private void botaoPesquisarLeiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoPesquisarLeiActionPerformed
      janelaPesquisarLei.setVisible(true);
      janelaPesquisarLei.limparTela();
    }//GEN-LAST:event_botaoPesquisarLeiActionPerformed

    private void botaoGerenciarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoGerenciarUsuarioActionPerformed
      janelaCadastroUsuario.getControlador().pesquisar();
      janelaCadastroUsuario.setVisible(true);
    }//GEN-LAST:event_botaoGerenciarUsuarioActionPerformed

    private void botaoSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSairActionPerformed
       System.exit(0);
    }//GEN-LAST:event_botaoSairActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAlterarLei;
    private javax.swing.JButton botaoCadastrarLei;
    private javax.swing.JButton botaoExcluirLei;
    private javax.swing.JButton botaoGerenciarUsuario;
    private javax.swing.JButton botaoPesquisarLei;
    private javax.swing.JButton botaoSair;
    private javax.swing.JLabel imgLogo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables
  private Controlador controlador;
  private JanelaCadastrarLei janelaCadastrarLei;
  private JanelaPesquisarLei janelaPesquisarLei;
  private JanelaRevogarLei janelaRevogarLei;
  private JanelaCadastroUsuario janelaCadastroUsuario;
  private JanelaAlterarLei janelaAlterarLei;
  private JanelaResultadoPesquisa janelaResultadoPesquisa;
  private JanelaModificarLei janelaModificarLei;

  public Controlador getControlador() {
    return controlador;
  }

  public void setControlador(Controlador c) {
    controlador = c;
  }

  public void exibirMensagem(String mensagem) {
    JOptionPane.showMessageDialog(this, mensagem);
  }

  public void exibirMensagemErro(String mensagem) {
    JOptionPane.showMessageDialog(this, mensagem, "Erro!", JOptionPane.ERROR_MESSAGE);
  }

  public void mostrarObjeto(Object o) {
    throw new UnsupportedOperationException("Ainda não suportado!");
  }

  public void mostrarObjetos(List l) {
    throw new UnsupportedOperationException("Ainda não suportado!");
  }
}
